@model LogSearchModel

@{
    //page title
    ViewBag.PageTitle = T("Admin.System.Log").Text;
    //active menu item (system name)
    NopHtml.SetActiveMenuItemSystemName("Log");
}

@{
    const string hideSearchBlockAttributeName = "LogPage.HideSearchBlock";
    var hideSearchBlock = await genericAttributeService.GetAttributeAsync<bool>(await workContext.GetCurrentCustomerAsync(), hideSearchBlockAttributeName);
}

<form asp-controller="Log" asp-action="List" method="post">
    <div class="content-header clearfix">
        <h1 class="float-left">
            @T("Admin.System.Log")
        </h1>
        <div class="float-right">
            <button type="button" id="delete-selected" name="delete-selected" class="btn btn-danger">
                <i class="far fa-trash-can"></i>
                @T("Admin.System.Log.DeleteSelected")
            </button>
            <nop-action-confirmation asp-button-id="delete-selected" />
            <button type="submit" id="clearall" name="clearall" class="btn btn-danger">
                <i class="far fa-trash-can"></i>
                @T("Admin.System.Log.ClearLog")
            </button>
            <nop-action-confirmation asp-button-id="clearall" asp-action="ClearAll" />
            @await Component.InvokeAsync(typeof(AdminWidgetViewComponent), new { widgetZone = AdminWidgetZones.LogListButtons, additionalData = Model })
        </div>
    </div>

    <section class="content">
        <div class="container-fluid">
            <div class="form-horizontal">
                <div class="cards-group">
                    <div class="card card-default">
                        <div class="card-body">
                            <p>
                                @T("Admin.System.Log.List.PremiumSupport", OfficialSite.PremiumSupportServices + Utm.OnAdminLogList)
                            </p>
                        </div>
                    </div>
                    <div class="card card-default card-search">
                        <div class="card-body">
                            <div class="row search-row @(!hideSearchBlock ? "opened" : "")" data-hideAttribute="@hideSearchBlockAttributeName">
                                <div class="search-text">@T("Admin.Common.Search")</div>
                                <div class="icon-search"><i class="fas fa-magnifying-glass" aria-hidden="true"></i></div>
                                <div class="icon-collapse"><i class="far fa-angle-@(!hideSearchBlock ? "up" : "down")" aria-hidden="true"></i></div>
                            </div>

                            <div class="search-body @(hideSearchBlock ? "closed" : "")">

                                <div class="row">
                                    <div class="col-md-5">
                                        <div class="form-group row">
                                            <div class="col-md-4">
                                                <nop-label asp-for="CreatedOnFrom" />
                                            </div>
                                            <div class="col-md-8">
                                                <nop-editor asp-for="CreatedOnFrom" />
                                            </div>
                                        </div>
                                        <div class="form-group row">
                                            <div class="col-md-4">
                                                <nop-label asp-for="CreatedOnTo" />
                                            </div>
                                            <div class="col-md-8">
                                                <nop-editor asp-for="CreatedOnTo" />
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-7">
                                        <div class="form-group row">
                                            <div class="col-md-4">
                                                <nop-label asp-for="Message" />
                                            </div>
                                            <div class="col-md-8">
                                                <nop-editor asp-for="Message" />
                                            </div>
                                        </div>
                                        <div class="form-group row">
                                            <div class="col-md-4">
                                                <nop-label asp-for="LogLevelId" />
                                            </div>
                                            <div class="col-md-8">
                                                <nop-select asp-for="LogLevelId" asp-items="Model.AvailableLogLevels" />
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="text-center col-12">
                                        <button type="button" id="search-log" class="btn btn-primary btn-search">
                                            <i class="fas fa-magnifying-glass"></i>
                                            @T("Admin.Common.Search")
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="card card-default">
                        <div class="card-body">
                            <nop-doc-reference asp-string-resource="@T("Admin.Documentation.Reference.Log", Docs.Log + Utm.OnAdmin)" />

                            @await Html.PartialAsync("Table", new DataTablesModel
                            {
                                Name = "log-grid",
                                UrlRead = new DataUrl("LogList", "Log", null),
                                SearchButtonId = "search-log",
                                Length = Model.PageSize,
                                LengthMenu = Model.AvailablePageSizes,
                                Filters = new List<FilterParameter>
                                {
                                    new FilterParameter(nameof(Model.CreatedOnFrom)),
                                    new FilterParameter(nameof(Model.CreatedOnTo)),
                                    new FilterParameter(nameof(Model.Message)),
                                    new FilterParameter(nameof(Model.LogLevelId))
                                },
                                ColumnCollection = new List<ColumnProperty>
                                {
                                    new ColumnProperty(nameof(LogModel.Id))
                                    {
                                        IsMasterCheckBox = true,
                                        Render = new RenderCheckBox("checkbox_log"),
                                        ClassName =  NopColumnClassDefaults.CenterAll,
                                        Width = "50"
                                    },
                                    new ColumnProperty(nameof(LogModel.LogLevel))
                                    {
                                        Title = T("Admin.System.Log.Fields.LogLevel").Text,
                                        Width = "100"
                                    },
                                    new ColumnProperty(nameof(LogModel.ShortMessage))
                                    {
                                        Title = T("Admin.System.Log.Fields.ShortMessage").Text,
                                        Encode = false
                                    },
                                    new ColumnProperty(nameof(LogModel.CreatedOn))
                                    {
                                        Title = T("Admin.System.Log.Fields.CreatedOn").Text,
                                        Width = "200",
                                        Render = new RenderDate()
                                    },
                                    new ColumnProperty(nameof(LogModel.Id))
                                    {
                                        Title = T("Admin.Common.View").Text,
                                        Width = "100",
                                        ClassName =  NopColumnClassDefaults.Button,
                                        Render = new RenderButtonView(new DataUrl("~/Admin/Log/View"))
                                    }
                                }
                            })

                            <script>
                                $(function() {
                                    //"delete selected" button
                                    $("#delete-selected-action-confirmation-submit-button").bind("click", function () {
                                        var postData = {
                                            selectedIds: selectedIds
                                        };
                                        addAntiForgeryToken(postData);
                                        $.ajax({
                                            cache: false,
                                            type: "POST",
                                            url: "@(Url.Action("DeleteSelected", "Log"))",
                                            data: postData,
                                            traditional: true,
                                            error: function (jqXHR, textStatus, errorThrown) {
                                                showAlert('deleteSelectedFailed', errorThrown);
                                            },
                                            complete: function (jqXHR, textStatus) {
                                                if (jqXHR.status === 204)
                                                {
                                                    showAlert('nothingSelectedAlert', '@T("Admin.Common.Alert.NothingSelected")');
                                                    return;
                                                }
                                                updateTable('#log-grid');
                                            }
                                        });
                                        $('#delete-selected-action-confirmation').modal('toggle');
                                        return false;
                                    });
                                });
                            </script>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
</form>
<nop-alert asp-alert-id="deleteSelectedFailed" />
<nop-alert asp-alert-id="nothingSelectedAlert" />
